import java.util.Arrays;

public class Fast {

	private void computeAllColliniarPoints(Point[] points) {

		Arrays.sort(points);

		Point[] sortedPoints = new Point[points.length];

		Point lastPoint = null;
		for (int i = 0; i < points.length; i++) {

			Point p1 = points[i];
			p1.draw();
			System.arraycopy(points, 0, sortedPoints, 0, points.length);
			Arrays.sort(sortedPoints, i, sortedPoints.length, p1.SLOPE_ORDER);

			int start = 0;
			int index = 0;
			double lastSlope = p1.slopeTo(sortedPoints[i]);
			for (int k = i + 1; k < sortedPoints.length; k++) {
				Point p2 = sortedPoints[k];
				double slopeP2P1 = p1.slopeTo(p2);

				if (slopeP2P1 == lastSlope) {
					index++;
				} else if (slopeP2P1 != lastSlope) {

					if (index >= 2
							&& (lastPoint == null || p1.slopeTo(lastPoint) != lastSlope)) {
						StdOut.print(p1);
						int kk = 0;
						for (kk = start; kk <= start + index; kk++) {
							Point p = sortedPoints[kk];
							p.draw();
							StdOut.print(" -> " + p);
						}
						sortedPoints[start + index].drawTo(sortedPoints[i]);
						StdOut.println();
						lastPoint = p1;
					}
					start = k;
					index = 0;
					lastSlope = p1.slopeTo(sortedPoints[start]);
				}

			}
			if (index >= 2
					&& (lastPoint == null || p1.slopeTo(lastPoint) != lastSlope)) {
				StdOut.print(p1);
				int kk = 0;
				for (kk = start; kk <= start + index; kk++) {
					Point p = sortedPoints[kk];
					p.draw();
					StdOut.print(" -> " + p);
				}
				sortedPoints[start + index].drawTo(sortedPoints[i]);
				StdOut.println();
				lastPoint = p1;
			}
		}
	}

	private void setUpDrawing() {
		StdDraw.setCanvasSize(800, 600);
		StdDraw.setPenColor(StdDraw.BLACK);
		StdDraw.setXscale(0, 32768);
		StdDraw.setYscale(0, 32768);
	}

	private Point[] getPoints(String file) {
		Point[] points = null;
		try {
			In in = new In(file);
			int n = in.readInt();
			points = new Point[n];
			for (int k = 0; k < n; k++) {
				points[k] = new Point(in.readInt(), in.readInt());
			}
		} catch (Exception e) {
			StdOut.print(e);
		}
		return points;
	}

	public static void main(String[] args) {

		Fast fastColliniar = new Fast();
		fastColliniar.setUpDrawing();
		Stopwatch stop = new Stopwatch();
		String argsFile = args[0];
		fastColliniar.computeAllColliniarPoints(fastColliniar
				.getPoints(argsFile));
		double elapsed = stop.elapsedTime();
		StdOut.print("Total:" + elapsed);
	}
}
